import { AxiosResponse } from 'axios'
import { ElMessage } from 'element-plus'

const setError = (response: AxiosResponse) => {
  // 失败
  if (response.data.code !== 0) {
    ElMessage.error({
      message: response.data.message || '未知错误',
      duration: 2 * 1000
    })
    return Promise.reject(response.data.message)
  }

  return response
}

export default setError
